package com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import java.util.Timer;

/**
 * @description 自动登录服务类
 * Created by 安帅 on 2016/5/27 15:14.
 * PackageName com.mlz.mlzMall.ui.activity.act.personal.NetworkRequest.
 * ProjectName mlzmall_android.
 */
public class AgainLoginService extends Service{
    Timer timer;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        int aa = intent.getIntExtra("again", 0);
        if (timer == null)
            timer = new Timer("againloginthread");
        System.out.println("AgainLoginService-----onStartCommand");
        TimeUtil timerUtils = new TimeUtil(getApplication());
        if (aa == 1) {
            System.out.println("AgainLoginService-----111");
            timer.schedule(timerUtils, 10, 15 * 60 * 1000);
        } else {
            System.out.println("AgainLoginService-----0000");
            timer.schedule(timerUtils, 15 * 60 * 1000, 15 * 60 * 1000);
        }
        return START_REDELIVER_INTENT;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        System.out.println("AgainLoginService-----onDestroy");
        if(timer != null) {
            timer.cancel();
        }
    }



}
